﻿#include "WrapperTools.h"
// core
#include "FITK_Kernel/FITKCore/FITKDataRepo.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
//framework
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
//python
#include "FITK_Kernel/FITKPython/FITKPythonInterface.h"
#include "PythonQtScriptingConsole.h"
//operator
#include "OperatorsInterface/GraphEventOperator.h"
//interface
#include "FITK_Interface/FITKInterfaceGeometry/FITKGeoCommandList.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKGeoInterfaceFactory.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoModelBox.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoModelSphere.h"
//component
#include "FITK_Component/FITKGeoCompOCC/FITKOCCModelSolid.h"
#include "FITK_Component/FITKGeoCompOCC/FITKOCCModelOperSolid.h"

#include <QMetaEnum>


namespace PyWrapperTool
{
    Interface::FITKAbsGeoCommand* WrapperTools::getGeoCommand(QString enumName)
    {
        if (enumName.isEmpty()) return nullptr;
        auto metaEnum = QMetaEnum::fromType<Interface::FITKGeoEnum::FITKGeometryComType>();
        int valueID = metaEnum.keyToValue(enumName.toLocal8Bit());
        if (valueID < 0) return nullptr;

        Interface::FITKInterfaceGeometryFactory* fac = Interface::FITKInterfaceGeometryFactory::getInstance();
        if (!fac) return nullptr;

        return fac->createCommand((Interface::FITKGeoEnum::FITKGeometryComType)valueID);
    }

    Interface::FITKAbsGeoCommand* WrapperTools::getGeoCommand(Interface::FITKGeoEnum::FITKGeometryComType t)
    {
        Interface::FITKInterfaceGeometryFactory* fac = Interface::FITKInterfaceGeometryFactory::getInstance();
        if (!fac) return nullptr;

        return fac->createCommand(t);
    }

    void WrapperTools::updateExecutionStatus(bool isStatus)
    {
        auto pyInstance = Python::FITKPythonInterface::getInstance();
        pyInstance->setExecutionStatus(isStatus);
    }
    void WrapperTools::printConsoleLog(const QString& str)
    {
        auto pyInstance = Python::FITKPythonInterface::getInstance();
        auto console = dynamic_cast<PythonQtScriptingConsole*>(pyInstance->getPyWidget());
        if (!console) return;
        console->stdErr(str);
    }
}